<!DOCTYPE html>
<html lang="" xml:lang="">
<head>

  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>3 Stata | 编程语言笔记</title>
  <meta name="description" content="3 Stata | 编程语言笔记" />
  <meta name="generator" content="bookdown 0.35 and GitBook 2.6.7" />

  <meta property="og:title" content="3 Stata | 编程语言笔记" />
  <meta property="og:type" content="book" />
  
  
  

  <meta name="twitter:card" content="summary" />
  <meta name="twitter:title" content="3 Stata | 编程语言笔记" />
  
  
  

<meta name="author" content="云腾足下" />



  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  
  
<link rel="prev" href="Julia.html"/>
<link rel="next" href="Matlab.html"/>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6/dist/fuse.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />








<link href="libs/anchor-sections-1.1.0/anchor-sections.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections-hash.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.1.0/anchor-sections.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  jax: ["input/TeX","output/SVG"],
  extensions: ["tex2jax.js","MathMenu.js","MathZoom.js"],
  TeX: {
    extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]
  }
});
</script>
<script type="text/javascript"
   src="../../../MathJax/MathJax.js">
</script>


<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>

<style type="text/css">
  
  div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
</style>

</head>

<body>



  <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">

    <div class="book-summary">
      <nav role="navigation">

<ul class="summary">
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>序</a></li>
<li class="chapter" data-level="1" data-path="Maple.html"><a href="Maple.html"><i class="fa fa-check"></i><b>1</b> Maple</a>
<ul>
<li class="chapter" data-level="1.1" data-path="Maple.html"><a href="Maple.html#快捷键"><i class="fa fa-check"></i><b>1.1</b> 快捷键</a></li>
<li class="chapter" data-level="1.2" data-path="Maple.html"><a href="Maple.html#几个基本的代数处理"><i class="fa fa-check"></i><b>1.2</b> 几个基本的代数处理</a></li>
<li class="chapter" data-level="1.3" data-path="Maple.html"><a href="Maple.html#产生序列"><i class="fa fa-check"></i><b>1.3</b> 产生序列</a></li>
<li class="chapter" data-level="1.4" data-path="Maple.html"><a href="Maple.html#函数定义"><i class="fa fa-check"></i><b>1.4</b> 函数定义</a>
<ul>
<li class="chapter" data-level="1.4.1" data-path="Maple.html"><a href="Maple.html#参数的宣称"><i class="fa fa-check"></i><b>1.4.1</b> 参数的宣称</a></li>
</ul></li>
<li class="chapter" data-level="1.5" data-path="Maple.html"><a href="Maple.html#控制流"><i class="fa fa-check"></i><b>1.5</b> 控制流</a></li>
<li class="chapter" data-level="1.6" data-path="Maple.html"><a href="Maple.html#画图"><i class="fa fa-check"></i><b>1.6</b> 画图</a></li>
<li class="chapter" data-level="1.7" data-path="Maple.html"><a href="Maple.html#矩阵"><i class="fa fa-check"></i><b>1.7</b> 矩阵</a></li>
<li class="chapter" data-level="1.8" data-path="Maple.html"><a href="Maple.html#一句话tips"><i class="fa fa-check"></i><b>1.8</b> 一句话Tips</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="Julia.html"><a href="Julia.html"><i class="fa fa-check"></i><b>2</b> Julia</a>
<ul>
<li class="chapter" data-level="2.1" data-path="Julia.html"><a href="Julia.html#julia的一些体会"><i class="fa fa-check"></i><b>2.1</b> Julia的一些体会</a>
<ul>
<li class="chapter" data-level="2.1.1" data-path="Julia.html"><a href="Julia.html#关于函数的参数"><i class="fa fa-check"></i><b>2.1.1</b> 关于函数的参数</a></li>
</ul></li>
<li class="chapter" data-level="2.2" data-path="Julia.html"><a href="Julia.html#julia的一些常用包"><i class="fa fa-check"></i><b>2.2</b> Julia的一些常用包</a>
<ul>
<li class="chapter" data-level="2.2.1" data-path="Julia.html"><a href="Julia.html#优化包"><i class="fa fa-check"></i><b>2.2.1</b> 优化包</a></li>
<li class="chapter" data-level="2.2.2" data-path="Julia.html"><a href="Julia.html#julia数值求根"><i class="fa fa-check"></i><b>2.2.2</b> Julia数值求根</a></li>
<li class="chapter" data-level="2.2.3" data-path="Julia.html"><a href="Julia.html#dataframes包"><i class="fa fa-check"></i><b>2.2.3</b> <code>DataFrames</code>包</a></li>
</ul></li>
<li class="chapter" data-level="2.3" data-path="Julia.html"><a href="Julia.html#julia的ide体验"><i class="fa fa-check"></i><b>2.3</b> Julia的IDE体验</a></li>
<li class="chapter" data-level="2.4" data-path="Julia.html"><a href="Julia.html#其他tips"><i class="fa fa-check"></i><b>2.4</b> 其他tips</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="Stata.html"><a href="Stata.html"><i class="fa fa-check"></i><b>3</b> Stata</a>
<ul>
<li class="chapter" data-level="3.1" data-path="Stata.html"><a href="Stata.html#数据处理"><i class="fa fa-check"></i><b>3.1</b> 数据处理</a></li>
<li class="chapter" data-level="3.2" data-path="Stata.html"><a href="Stata.html#回归相关"><i class="fa fa-check"></i><b>3.2</b> 回归相关</a>
<ul>
<li class="chapter" data-level="3.2.1" data-path="Stata.html"><a href="Stata.html#描述性统计和回归结果导出"><i class="fa fa-check"></i><b>3.2.1</b> 描述性统计和回归结果导出</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="Stata.html"><a href="Stata.html#一些外部命令"><i class="fa fa-check"></i><b>3.3</b> 一些外部命令</a></li>
<li class="chapter" data-level="3.4" data-path="Stata.html"><a href="Stata.html#stata对某个变量随机抽样"><i class="fa fa-check"></i><b>3.4</b> stata对某个变量随机抽样</a></li>
<li class="chapter" data-level="3.5" data-path="Stata.html"><a href="Stata.html#stata调用r"><i class="fa fa-check"></i><b>3.5</b> Stata调用R</a></li>
<li class="chapter" data-level="3.6" data-path="Stata.html"><a href="Stata.html#miscellaneous"><i class="fa fa-check"></i><b>3.6</b> Miscellaneous</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="Matlab.html"><a href="Matlab.html"><i class="fa fa-check"></i><b>4</b> Matlab</a>
<ul>
<li class="chapter" data-level="4.1" data-path="Matlab.html"><a href="Matlab.html#一句话tips-1"><i class="fa fa-check"></i><b>4.1</b> 一句话Tips</a></li>
<li class="chapter" data-level="4.2" data-path="Matlab.html"><a href="Matlab.html#带名称和缺省值的参数设置"><i class="fa fa-check"></i><b>4.2</b> 带名称和缺省值的参数设置</a></li>
<li class="chapter" data-level="4.3" data-path="Matlab.html"><a href="Matlab.html#窗口输出到文本"><i class="fa fa-check"></i><b>4.3</b> 窗口输出到文本</a></li>
<li class="chapter" data-level="4.4" data-path="Matlab.html"><a href="Matlab.html#gvar-toolbox使用报告"><i class="fa fa-check"></i><b>4.4</b> GVAR Toolbox使用报告</a>
<ul>
<li class="chapter" data-level="4.4.1" data-path="Matlab.html"><a href="Matlab.html#数据输入"><i class="fa fa-check"></i><b>4.4.1</b> 数据输入</a></li>
<li class="chapter" data-level="4.4.2" data-path="Matlab.html"><a href="Matlab.html#模型设定"><i class="fa fa-check"></i><b>4.4.2</b> 模型设定</a></li>
<li class="chapter" data-level="4.4.3" data-path="Matlab.html"><a href="Matlab.html#一些坑"><i class="fa fa-check"></i><b>4.4.3</b> 一些坑</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="5" data-path="git操作流程.html"><a href="git操作流程.html"><i class="fa fa-check"></i><b>5</b> git操作流程</a>
<ul>
<li class="chapter" data-level="5.1" data-path="git操作流程.html"><a href="git操作流程.html#基本语法"><i class="fa fa-check"></i><b>5.1</b> 基本语法</a></li>
<li class="chapter" data-level="5.2" data-path="git操作流程.html"><a href="git操作流程.html#生成公钥"><i class="fa fa-check"></i><b>5.2</b> 生成公钥</a></li>
<li class="chapter" data-level="5.3" data-path="git操作流程.html"><a href="git操作流程.html#本地库操作"><i class="fa fa-check"></i><b>5.3</b> 本地库操作</a></li>
<li class="chapter" data-level="5.4" data-path="git操作流程.html"><a href="git操作流程.html#关联远程库码云"><i class="fa fa-check"></i><b>5.4</b> 关联远程库（码云）</a></li>
<li class="chapter" data-level="5.5" data-path="git操作流程.html"><a href="git操作流程.html#打开vi后的操作"><i class="fa fa-check"></i><b>5.5</b> 打开VI后的操作</a></li>
<li class="chapter" data-level="5.6" data-path="git操作流程.html"><a href="git操作流程.html#给递交进行标记"><i class="fa fa-check"></i><b>5.6</b> 给递交进行标记</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="C.html"><a href="C.html"><i class="fa fa-check"></i><b>6</b> C语言</a>
<ul>
<li class="chapter" data-level="6.1" data-path="C.html"><a href="C.html#一句话tips-2"><i class="fa fa-check"></i><b>6.1</b> 一句话Tips</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="Latex.html"><a href="Latex.html"><i class="fa fa-check"></i><b>7</b> Latex</a>
<ul>
<li class="chapter" data-level="7.1" data-path="Latex.html"><a href="Latex.html#一句话tips-3"><i class="fa fa-check"></i><b>7.1</b> 一句话Tips</a></li>
<li class="chapter" data-level="7.2" data-path="Latex.html"><a href="Latex.html#使用pdfpages包插入pdf页面"><i class="fa fa-check"></i><b>7.2</b> 使用<code>pdfpages</code>包插入PDF页面</a></li>
<li class="chapter" data-level="7.3" data-path="Latex.html"><a href="Latex.html#记录几个快捷键"><i class="fa fa-check"></i><b>7.3</b> 记录几个快捷键</a></li>
<li class="chapter" data-level="7.4" data-path="Latex.html"><a href="Latex.html#手动安装新的宏包"><i class="fa fa-check"></i><b>7.4</b> 手动安装新的宏包</a></li>
<li class="chapter" data-level="7.5" data-path="Latex.html"><a href="Latex.html#beamer相关"><i class="fa fa-check"></i><b>7.5</b> <code>beamer</code>相关</a></li>
<li class="chapter" data-level="7.6" data-path="Latex.html"><a href="Latex.html#表格相关"><i class="fa fa-check"></i><b>7.6</b> 表格相关</a>
<ul>
<li class="chapter" data-level="7.6.1" data-path="Latex.html"><a href="Latex.html#长表格"><i class="fa fa-check"></i><b>7.6.1</b> 长表格</a></li>
</ul></li>
<li class="chapter" data-level="7.7" data-path="Latex.html"><a href="Latex.html#章节标题格式修改"><i class="fa fa-check"></i><b>7.7</b> 章节标题格式修改</a></li>
<li class="chapter" data-level="7.8" data-path="Latex.html"><a href="Latex.html#数学公式相关"><i class="fa fa-check"></i><b>7.8</b> 数学公式相关</a>
<ul>
<li class="chapter" data-level="7.8.1" data-path="Latex.html"><a href="Latex.html#数学公式左对齐"><i class="fa fa-check"></i><b>7.8.1</b> 数学公式左对齐</a></li>
</ul></li>
<li class="chapter" data-level="7.9" data-path="Latex.html"><a href="Latex.html#中文字体加粗"><i class="fa fa-check"></i><b>7.9</b> 中文字体加粗</a></li>
<li class="chapter" data-level="7.10" data-path="Latex.html"><a href="Latex.html#使用某种常用字体"><i class="fa fa-check"></i><b>7.10</b> 使用某种常用字体</a>
<ul>
<li class="chapter" data-level="7.10.1" data-path="Latex.html"><a href="Latex.html#如何使用一个新的字体"><i class="fa fa-check"></i><b>7.10.1</b> 如何使用一个新的字体？</a></li>
</ul></li>
<li class="chapter" data-level="7.11" data-path="Latex.html"><a href="Latex.html#我的r代码排版模版"><i class="fa fa-check"></i><b>7.11</b> 我的R代码排版模版</a>
<ul>
<li class="chapter" data-level="7.11.1" data-path="Latex.html"><a href="Latex.html#listings包"><i class="fa fa-check"></i><b>7.11.1</b> <code>listings</code>包</a></li>
<li class="chapter" data-level="7.11.2" data-path="Latex.html"><a href="Latex.html#fancyvrb包"><i class="fa fa-check"></i><b>7.11.2</b> <code>fancyvrb</code>包</a></li>
</ul></li>
<li class="chapter" data-level="7.12" data-path="Latex.html"><a href="Latex.html#latex插入附录"><i class="fa fa-check"></i><b>7.12</b> latex插入附录</a></li>
<li class="chapter" data-level="7.13" data-path="Latex.html"><a href="Latex.html#latex参考文献的编码思路"><i class="fa fa-check"></i><b>7.13</b> latex参考文献的编码思路</a>
<ul>
<li class="chapter" data-level="7.13.1" data-path="Latex.html"><a href="Latex.html#参考文献较少的情况"><i class="fa fa-check"></i><b>7.13.1</b> 参考文献较少的情况</a></li>
<li class="chapter" data-level="7.13.2" data-path="Latex.html"><a href="Latex.html#参考文献较多的情况"><i class="fa fa-check"></i><b>7.13.2</b> 参考文献较多的情况</a></li>
<li class="chapter" data-level="7.13.3" data-path="Latex.html"><a href="Latex.html#如何将文献引用作为上标出现"><i class="fa fa-check"></i><b>7.13.3</b> 如何将文献引用作为上标出现？</a></li>
</ul></li>
<li class="chapter" data-level="7.14" data-path="Latex.html"><a href="Latex.html#一些文体的模版"><i class="fa fa-check"></i><b>7.14</b> 一些文体的模版</a>
<ul>
<li class="chapter" data-level="7.14.1" data-path="Latex.html"><a href="Latex.html#社科申报课题部分模版"><i class="fa fa-check"></i><b>7.14.1</b> 社科申报课题部分模版</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="8" data-path="Blog.html"><a href="Blog.html"><i class="fa fa-check"></i><b>8</b> 博客</a></li>
<li class="chapter" data-level="9" data-path="OS.html"><a href="OS.html"><i class="fa fa-check"></i><b>9</b> macOS操作系统</a>
<ul>
<li class="chapter" data-level="9.1" data-path="OS.html"><a href="OS.html#一句话tips-4"><i class="fa fa-check"></i><b>9.1</b> 一句话Tips</a></li>
<li class="chapter" data-level="9.2" data-path="OS.html"><a href="OS.html#安装和配置latex"><i class="fa fa-check"></i><b>9.2</b> 安装和配置Latex</a></li>
<li class="chapter" data-level="9.3" data-path="OS.html"><a href="OS.html#homebrew"><i class="fa fa-check"></i><b>9.3</b> Homebrew</a></li>
<li class="chapter" data-level="9.4" data-path="OS.html"><a href="OS.html#挂载外置磁盘"><i class="fa fa-check"></i><b>9.4</b> 挂载外置磁盘</a></li>
</ul></li>
<li class="chapter" data-level="10" data-path="Mathematica.html"><a href="Mathematica.html"><i class="fa fa-check"></i><b>10</b> Mathematica</a>
<ul>
<li class="chapter" data-level="10.1" data-path="Mathematica.html"><a href="Mathematica.html#快捷键-1"><i class="fa fa-check"></i><b>10.1</b> 快捷键</a></li>
</ul></li>
<li class="chapter" data-level="11" data-path="Python.html"><a href="Python.html"><i class="fa fa-check"></i><b>11</b> python</a>
<ul>
<li class="chapter" data-level="11.1" data-path="Python.html"><a href="Python.html#vscode下配置python"><i class="fa fa-check"></i><b>11.1</b> VSCode下配置python</a></li>
</ul></li>
<li class="chapter" data-level="12" data-path="Other.html"><a href="Other.html"><i class="fa fa-check"></i><b>12</b> 其他小众软件</a>
<ul>
<li class="chapter" data-level="12.1" data-path="Other.html"><a href="Other.html#pdf文件压缩"><i class="fa fa-check"></i><b>12.1</b> PDF文件压缩</a></li>
<li class="chapter" data-level="12.2" data-path="Other.html"><a href="Other.html#eviews编程"><i class="fa fa-check"></i><b>12.2</b> Eviews编程</a></li>
<li class="chapter" data-level="12.3" data-path="Other.html"><a href="Other.html#gauss"><i class="fa fa-check"></i><b>12.3</b> GAUSS</a>
<ul>
<li class="chapter" data-level="12.3.1" data-path="Other.html"><a href="Other.html#系统函数"><i class="fa fa-check"></i><b>12.3.1</b> 系统函数</a></li>
</ul></li>
<li class="chapter" data-level="12.4" data-path="Other.html"><a href="Other.html#zotero"><i class="fa fa-check"></i><b>12.4</b> Zotero</a></li>
<li class="chapter" data-level="12.5" data-path="Other.html"><a href="Other.html#word中插入公式"><i class="fa fa-check"></i><b>12.5</b> Word中插入公式</a>
<ul>
<li class="chapter" data-level="12.5.1" data-path="Other.html"><a href="Other.html#自带的公式输入"><i class="fa fa-check"></i><b>12.5.1</b> 自带的公式输入</a></li>
<li class="chapter" data-level="12.5.2" data-path="Other.html"><a href="Other.html#公式编号的其他方法"><i class="fa fa-check"></i><b>12.5.2</b> 公式编号的其他方法</a></li>
<li class="chapter" data-level="12.5.3" data-path="Other.html"><a href="Other.html#利用texsword编辑器"><i class="fa fa-check"></i><b>12.5.3</b> 利用TexsWord编辑器</a></li>
</ul></li>
<li class="chapter" data-level="12.6" data-path="Other.html"><a href="Other.html#noteexpress样式设置"><i class="fa fa-check"></i><b>12.6</b> NoteExpress样式设置</a></li>
<li class="chapter" data-level="12.7" data-path="Other.html"><a href="Other.html#filezilla"><i class="fa fa-check"></i><b>12.7</b> FileZilla</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="references.html"><a href="references.html"><i class="fa fa-check"></i>References</a></li>
</ul>

      </nav>
    </div>

    <div class="book-body">
      <div class="body-inner">
        <div class="book-header" role="navigation">
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">编程语言笔记</a>
          </h1>
        </div>

        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <section class="normal" id="section-">
<div id="Stata" class="section level1 hasAnchor" number="3">
<h1><span class="header-section-number">3</span> Stata<a href="Stata.html#Stata" class="anchor-section" aria-label="Anchor link to header"></a></h1>
<div id="数据处理" class="section level2 hasAnchor" number="3.1">
<h2><span class="header-section-number">3.1</span> 数据处理<a href="Stata.html#数据处理" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<ol style="list-style-type: decimal">
<li>生成观测的脚标，即1:nrow(x): <code>gen yr = _n //</code></li>
<li>回归完成，使用<code>predict</code>可以得到拟合值，残差等序列。如<code>predict yres, resid</code>则得到名为<code>yres</code>的残差。</li>
<li><code>matrix list A</code>: 显示矩阵</li>
<li><code>outfile v1 v2 v3 using mydata.csv, comma</code> 输出逗号分割的csv文件。</li>
<li>外部命令把矩阵保存为dta格式：<code>matsave A, replace p("matrices") saving</code>意味着把矩阵A保存在<code>dir/matrices/</code>下。</li>
<li>季节调整，外部命令<code>sax12</code></li>
<li>从变量名<code>income</code>生成一个新的变量名如<code>income_y</code>，则可以如下操作：</li>
</ol>
<div class="sourceCode" id="cb21"><pre class="sourceCode stata"><code class="sourceCode stata"><span id="cb21-1"><a href="Stata.html#cb21-1" tabindex="-1"></a><span class="kw">local</span> xvar income</span>
<span id="cb21-2"><a href="Stata.html#cb21-2" tabindex="-1"></a><span class="kw">local</span> yvar <span class="ot">`xvar&#39;</span>_y</span></code></pre></div>
<p>此时的<code>yvar</code>就是<code>income_y</code>。</p>
</div>
<div id="回归相关" class="section level2 hasAnchor" number="3.2">
<h2><span class="header-section-number">3.2</span> 回归相关<a href="Stata.html#回归相关" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<ul>
<li><code>#</code>是所有分类交互，<code>##</code>是仅仅两个分类交互。</li>
<li>获得残差。估计完以后，使用命令：<code>predict e, r //e是生成的残差变量名，r表明生成残差</code>。</li>
<li>将回归后的系数存入数据集中，然后即可导出。</li>
</ul>
<pre><code>mat b = e(b)&#39;
svmat double b, n(beta)</code></pre>
<ul>
<li>滞后、超前、差分变量。<code>L.x L2.x F.x F2.x D.x D2.x</code></li>
<li>字符串转因子变量：<code>encode str_var, g(newvar)</code></li>
<li>恩格尔格兰杰两步法：<code>egranger</code>是外部命令。</li>
<li>滚动估计：<code>_b,_se</code>意味着保存回归系数和标准误，200的窗口样本，原来数据集的变量合并到新的保存的数据集betas中去。</li>
</ul>
<div class="sourceCode" id="cb23"><pre class="sourceCode stata"><code class="sourceCode stata"><span id="cb23-1"><a href="Stata.html#cb23-1" tabindex="-1"></a><span class="kw">rolling</span> _b _se, <span class="kw">window</span>(200) <span class="kw">saving</span>(betas, <span class="kw">replace</span>) <span class="kw">keep</span>(<span class="fu">date</span>):<span class="kw">regress</span> ibmadj spxadj</span></code></pre></div>
<div id="描述性统计和回归结果导出" class="section level3 hasAnchor" number="3.2.1">
<h3><span class="header-section-number">3.2.1</span> 描述性统计和回归结果导出<a href="Stata.html#描述性统计和回归结果导出" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<ul>
<li>一个例子：</li>
</ul>
<div class="sourceCode" id="cb24"><pre class="sourceCode stata"><code class="sourceCode stata"><span id="cb24-1"><a href="Stata.html#cb24-1" tabindex="-1"></a><span class="kw">ssc</span> install sum2docx</span>
<span id="cb24-2"><a href="Stata.html#cb24-2" tabindex="-1"></a>sum2docx pay stock fund finance income age edu sex hukou marriage bond <span class="co">///</span></span>
<span id="cb24-3"><a href="Stata.html#cb24-3" tabindex="-1"></a>insurance deposit income depositDum RiskDum InsDum <span class="kw">using</span>  pm.docx, <span class="kw">replace</span> <span class="co">///</span></span>
<span id="cb24-4"><a href="Stata.html#cb24-4" tabindex="-1"></a>        <span class="kw">stats</span>(<span class="kw">N</span> <span class="kw">mean</span>(%9.2f) <span class="fu">sd</span> <span class="fu">min</span>(%9.0g) <span class="co">///</span></span>
<span id="cb24-5"><a href="Stata.html#cb24-5" tabindex="-1"></a>        <span class="kw">median</span>(%9.0g) <span class="fu">max</span>(%9.0g))  <span class="co">///</span></span>
<span id="cb24-6"><a href="Stata.html#cb24-6" tabindex="-1"></a>        <span class="bn">title</span>(<span class="st">&quot;表 1: 描述性统计&quot;</span>)</span>
<span id="cb24-7"><a href="Stata.html#cb24-7" tabindex="-1"></a><span class="kw">ssc</span> install reg2docx</span>
<span id="cb24-8"><a href="Stata.html#cb24-8" tabindex="-1"></a><span class="kw">probit</span> depositDum pay income age edu sex hukou marriage</span>
<span id="cb24-9"><a href="Stata.html#cb24-9" tabindex="-1"></a><span class="kw">est</span> <span class="kw">store</span> p1</span>
<span id="cb24-10"><a href="Stata.html#cb24-10" tabindex="-1"></a><span class="kw">probit</span> RiskDum pay income age edu sex hukou marriage</span>
<span id="cb24-11"><a href="Stata.html#cb24-11" tabindex="-1"></a><span class="kw">est</span> <span class="kw">store</span> p2</span>
<span id="cb24-12"><a href="Stata.html#cb24-12" tabindex="-1"></a><span class="kw">probit</span> InsDum pay income age edu sex hukou marriage</span>
<span id="cb24-13"><a href="Stata.html#cb24-13" tabindex="-1"></a><span class="kw">est</span> <span class="kw">store</span> p3</span>
<span id="cb24-14"><a href="Stata.html#cb24-14" tabindex="-1"></a>reg2docx p1 p2 p3 <span class="kw">using</span> pm.docx, <span class="kw">append</span> <span class="bn">title</span>(<span class="st">&quot;表2: Probit回归结果&quot;</span>) scalars(<span class="kw">r2_p</span> <span class="kw">N</span>)</span></code></pre></div>
<ul>
<li>另一个例子：输出回归结果到csv文件</li>
</ul>
<div class="sourceCode" id="cb25"><pre class="sourceCode stata"><code class="sourceCode stata"><span id="cb25-1"><a href="Stata.html#cb25-1" tabindex="-1"></a><span class="kw">reg</span> <span class="fu">y</span> x</span>
<span id="cb25-2"><a href="Stata.html#cb25-2" tabindex="-1"></a><span class="kw">est</span> <span class="kw">store</span> m1</span>
<span id="cb25-3"><a href="Stata.html#cb25-3" tabindex="-1"></a>esttab m1 m2 m3 <span class="kw">using</span> rlt.csv, <span class="kw">replace</span> <span class="co">//输出回归结果</span></span>
<span id="cb25-4"><a href="Stata.html#cb25-4" tabindex="-1"></a>esttab <span class="fu">e</span>(b) <span class="kw">using</span> rlt.csv, <span class="kw">replace</span>  <span class="co">//输出回归系数</span></span></code></pre></div>
</div>
</div>
<div id="一些外部命令" class="section level2 hasAnchor" number="3.3">
<h2><span class="header-section-number">3.3</span> 一些外部命令<a href="Stata.html#一些外部命令" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<ul>
<li><code>diff</code>可以做DID，PSM-DID，分位DID</li>
<li><code>xtnptimevar</code>：非参时变面板固定效应系数估计。方法是Li, Chen and Gao (2011)。</li>
<li><code>xtfixedcoeftvcu</code>：Hsiao(2014)的书上变系数中的固定系数估计命令。</li>
<li><code>xtsemipar</code>: Baltagi and Li (2002)的半参部分线性固定效应面板估计。代码缺陷在于非参数只能是一个变量。</li>
<li><code>xthreg</code>，Hansen(1999)静态面板阈值回归。</li>
<li>连享会在微信上有很多有用的资源，其发布的命令<code>lianxh</code>可以搜索这些资源。</li>
</ul>
<div class="sourceCode" id="cb26"><pre class="sourceCode stata"><code class="sourceCode stata"><span id="cb26-1"><a href="Stata.html#cb26-1" tabindex="-1"></a><span class="kw">ssc</span> install lianxh <span class="co">// 安装</span></span>
<span id="cb26-2"><a href="Stata.html#cb26-2" tabindex="-1"></a><span class="kw">help</span> lianxh</span>
<span id="cb26-3"><a href="Stata.html#cb26-3" tabindex="-1"></a>lianxh DID+Stata <span class="co">// and 搜索DID和stata关键词</span></span></code></pre></div>
</div>
<div id="stata对某个变量随机抽样" class="section level2 hasAnchor" number="3.4">
<h2><span class="header-section-number">3.4</span> stata对某个变量随机抽样<a href="Stata.html#stata对某个变量随机抽样" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p><strong>问题</strong> 回归以后，如何对残差进行自助抽样？stata里面对某个变量随机抽样会比较麻烦一些。它有一个函数<code>sample</code>, 但是它是对整个数据集抽样。要对某个变量抽样，需要曲线救国。</p>
<p>解决的思路：</p>
<ol style="list-style-type: decimal">
<li>首先保存原来的数据集；</li>
<li>然后删掉其他变量，仅保留残差；</li>
<li><code>sample</code>残差，然后<code>merge</code>刚刚保存的数据集。这就得到了随机抽样后的残差。</li>
</ol>
<p>代码</p>
<div class="sourceCode" id="cb27"><pre class="sourceCode stata"><code class="sourceCode stata"><span id="cb27-1"><a href="Stata.html#cb27-1" tabindex="-1"></a>cd E:\17_HuaDong\reserch\GVAR\RCode\GVAR_UsingR2e</span>
<span id="cb27-2"><a href="Stata.html#cb27-2" tabindex="-1"></a><span class="kw">use</span> regdata, <span class="kw">replace</span></span>
<span id="cb27-3"><a href="Stata.html#cb27-3" tabindex="-1"></a><span class="kw">gen</span> time = <span class="dt">_n</span></span>
<span id="cb27-4"><a href="Stata.html#cb27-4" tabindex="-1"></a><span class="kw">tsset</span> time</span>
<span id="cb27-5"><a href="Stata.html#cb27-5" tabindex="-1"></a>threshold <span class="fu">y</span>, threshvar(thV) regionvars(<span class="kw">V</span>*) <span class="kw">trim</span>(20) nthresholds(1)</span>
<span id="cb27-6"><a href="Stata.html#cb27-6" tabindex="-1"></a><span class="kw">predict</span> <span class="kw">double</span> eps, residuals</span>
<span id="cb27-7"><a href="Stata.html#cb27-7" tabindex="-1"></a><span class="kw">save</span> GVAR, <span class="kw">replace</span></span>
<span id="cb27-8"><a href="Stata.html#cb27-8" tabindex="-1"></a><span class="kw">keep</span> eps</span>
<span id="cb27-9"><a href="Stata.html#cb27-9" tabindex="-1"></a><span class="kw">bsample</span> 100</span>
<span id="cb27-10"><a href="Stata.html#cb27-10" tabindex="-1"></a><span class="kw">merge</span> 1:1 <span class="dt">_n</span> <span class="kw">using</span> GVAR</span></code></pre></div>
</div>
<div id="stata调用r" class="section level2 hasAnchor" number="3.5">
<h2><span class="header-section-number">3.5</span> Stata调用R<a href="Stata.html#stata调用r" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<ul>
<li>安装rsource包</li>
</ul>
<div class="sourceCode" id="cb28"><pre class="sourceCode stata"><code class="sourceCode stata"><span id="cb28-1"><a href="Stata.html#cb28-1" tabindex="-1"></a><span class="kw">ssc</span> install rsource</span></code></pre></div>
<ul>
<li>直接在do文件中写R代码</li>
</ul>
<div class="sourceCode" id="cb29"><pre class="sourceCode stata"><code class="sourceCode stata"><span id="cb29-1"><a href="Stata.html#cb29-1" tabindex="-1"></a><span class="co">//调用R软件 END_OF_R是设定一个标志，表示用这个表示结束</span></span>
<span id="cb29-2"><a href="Stata.html#cb29-2" tabindex="-1"></a>rsource, terminator(END_OF_R) rpath(D:\Program Files\R-3.5.0\<span class="bn">bin</span>\R.exe) <span class="co">///</span></span>
<span id="cb29-3"><a href="Stata.html#cb29-3" tabindex="-1"></a>roptions(--vanilla)  <span class="co">// 修改路径</span></span>
<span id="cb29-4"><a href="Stata.html#cb29-4" tabindex="-1"></a>rm(<span class="ot">list</span> = ls())</span>
<span id="cb29-5"><a href="Stata.html#cb29-5" tabindex="-1"></a>library(foreign)</span>
<span id="cb29-6"><a href="Stata.html#cb29-6" tabindex="-1"></a>library(tidyverse)</span>
<span id="cb29-7"><a href="Stata.html#cb29-7" tabindex="-1"></a>a318 &lt;- read.dta(&#39;E:/25_PartTimeJob/1810318/a318.dta&#39;) # 修改路径,记住，是反斜杠</span>
<span id="cb29-8"><a href="Stata.html#cb29-8" tabindex="-1"></a>a318 &lt;- <span class="kw">as</span>.tibble(a318)</span>
<span id="cb29-9"><a href="Stata.html#cb29-9" tabindex="-1"></a>library(PSTR)</span>
<span id="cb29-10"><a href="Stata.html#cb29-10" tabindex="-1"></a>regdata &lt;- NewPSTR(a318,dep = &#39;ev&#39;,indep = c(&#39;cs&#39;,&#39;as&#39;,&#39;p&#39;,&#39;es&#39;),</span>
<span id="cb29-11"><a href="Stata.html#cb29-11" tabindex="-1"></a>                   indep_k = c(&#39;cs&#39;,&#39;as&#39;,&#39;p&#39;,&#39;es&#39;),tvars = &#39;go&#39;,iT = nrow(a318),</span>
<span id="cb29-12"><a href="Stata.html#cb29-12" tabindex="-1"></a>                   im = 1)</span>
<span id="cb29-13"><a href="Stata.html#cb29-13" tabindex="-1"></a>pstr &lt;- LinTest(regdata)</span>
<span id="cb29-14"><a href="Stata.html#cb29-14" tabindex="-1"></a><span class="kw">print</span>(pstr,&#39;tests&#39;)</span>
<span id="cb29-15"><a href="Stata.html#cb29-15" tabindex="-1"></a>rlt &lt;- EstPSTR(regdata,im=1,iq=1)</span>
<span id="cb29-16"><a href="Stata.html#cb29-16" tabindex="-1"></a><span class="kw">print</span>(rlt,&#39;estimates&#39;)</span>
<span id="cb29-17"><a href="Stata.html#cb29-17" tabindex="-1"></a>END_OF_R</span></code></pre></div>
<ul>
<li>在do 文件中调用R代码</li>
</ul>
<div class="sourceCode" id="cb30"><pre class="sourceCode stata"><code class="sourceCode stata"><span id="cb30-1"><a href="Stata.html#cb30-1" tabindex="-1"></a> rsource <span class="kw">using</span> nitz2.R, rpath(D:\Program Files\R-3.5.0\<span class="bn">bin</span>\R.exe) roptions(--vanilla)</span></code></pre></div>
</div>
<div id="miscellaneous" class="section level2 hasAnchor" number="3.6">
<h2><span class="header-section-number">3.6</span> Miscellaneous<a href="Stata.html#miscellaneous" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<ul>
<li><code>adopath</code>可以查看ado文件存放的路径，如果你安装了外部包，想查看它的源代码，可以用这个命令看看路径在哪里。比如我的默认就在<code>"C:\Users\Administrator\ado\plus/"</code>。</li>
<li><code>wbopendata</code>包的使用</li>
</ul>
<div class="sourceCode" id="cb31"><pre class="sourceCode stata"><code class="sourceCode stata"><span id="cb31-1"><a href="Stata.html#cb31-1" tabindex="-1"></a><span class="kw">ssc</span> install wbopendata <span class="co">//下载世界银行数据</span></span>
<span id="cb31-2"><a href="Stata.html#cb31-2" tabindex="-1"></a><span class="kw">db</span> wbopendata <span class="co">//一个GUI下载界面</span></span></code></pre></div>
<ul>
<li><code>icio</code>投入产出分析，koopman et al. (2014)的方法</li>
<li>stata15有一个阈值非线性估计命令<code>threshold</code>非常好用：通过AIC，SC和HQIC来选择阈值的个数，最小的就是最合适的。</li>
<li><code>egi</code>：计算EG指数。</li>
<li>stata中文乱码问题</li>
</ul>
<p>第一步，先用命令<code>unicode analyze Data035.dta</code> 分析数据集的编码</p>
<p>第二步，用命令<code>unicode encoding set gb18030</code>设置编码</p>
<p>第三步，用命令<code>unicode   translate "Data035.dta", transutf8</code>转换编码</p>
<p>备注：有时某些变量无法转化，可使用<code>invalid(mark)</code>选项。</p>

</div>
</div>
            </section>

          </div>
        </div>
      </div>
<a href="Julia.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="Matlab.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
    </div>
  </div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"whatsapp": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": ["CBook.pdf"],
"search": {
"engine": "fuse",
"options": null
},
"toc": {
"collapse": "subsection"
}
});
});
</script>

<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/latest.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:")
      if (/^https?:/.test(src))
        src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>
</body>

</html>
